<?php

    /**
     * This class is a tool to connect the php server with a mysql db.
     * @author eKameleon
     */
    class MysqlConnector 
    {
        
        /**
         * Creates a new MysqlConnector instance.
         */
        function MysqlConnector( $host, $user, $pass, $dbname ) 
        {
            $this->host = $host ;
            $this->user = $user ;
            $this->pass = $pass ;
            $this->name = $dbname ;
        }
        
        /**
         * The host of the db.
         */
        var $host ;
        
        /**
         * The last id inserted.
         */
        var $lastID ;
                
        
        /**
         * The name of the db.
         */
        var $name ;
        
        /**
         * The password of the db.
         */
        var $pass ;
        
        /**
         * The name of the db user.
         */
        var $user ;
        
        /**
         * Returns the result of a MYSQL query.
         */
        function getResult ( $query ) 
        {
            
            $connect = mysql_connect ( $this->host, $this->user, $this->pass )     
                or trigger_error("Could not connect : " . mysql_error()) ;
            
            $bdd = mysql_select_db ( $this->name ) 
                or trigger_error("Could not connect : " . mysql_error()) ;
            
            $result = mysql_query( $query ) 
                or trigger_error("Error executing query : " . mysql_error()) ;
                
            $this->lastID = mysql_insert_id() ;
            
            return $result ;
        }
        
        /*
         * Return the lastId property.
         */
        function getLastID()
        {
            return $this->lastID;
        }
    }
    
?>